﻿namespace UnityEditor.Graphs.AnimationStateMachine
{
    using NUnit.Framework;
    using System;
    using System.Linq;
    using UnityEditor;
    using UnityEditor.Graphs;
    using UnityEditorInternal;
    using UnityEngine;

    internal class StateMachineNode : UnityEditor.Graphs.AnimationStateMachine.Node
    {
        public StateMachine stateMachine;

        private void CopyStateMachineCallback()
        {
            this.stateMachine.SyncLocalTransitionsFrom(AnimatorControllerTool.tool.stateMachineGraph.rootStateMachine);
            Unsupported.CopyStateMachineToPasteboard(this.stateMachine);
        }

        public override void Move()
        {
            base.Move();
            if (this.stateMachine == AnimatorControllerTool.tool.stateMachineGraph.parentStateMachine)
            {
                AnimatorControllerTool.tool.stateMachineGraph.activeStateMachine.parentStateMachinePosition = (Vector3) new Vector2(this.position.x, this.position.y);
            }
            else
            {
                AnimatorControllerTool.tool.stateMachineGraph.activeStateMachine.SetStateMachinePosition(this.stateMachine, (Vector3) new Vector2(this.position.x, this.position.y));
            }
        }

        internal override void NodeUI(UnityEditor.Graphs.GraphGUI host)
        {
            base.graphGUI = host as UnityEditor.Graphs.AnimationStateMachine.GraphGUI;
            Assert.NotNull(base.graphGUI);
            if (UnityEditor.Graphs.AnimationStateMachine.Node.IsLeftClick())
            {
                host.edgeGUI.EndSlotDragging(base.inputSlots.First<Slot>(), true);
            }
            if (UnityEditor.Graphs.AnimationStateMachine.Node.IsDoubleClick())
            {
                if (this.stateMachine == base.graphGUI.stateMachineGraph.parentStateMachine)
                {
                    base.graphGUI.tool.GoToBreadCrumbTarget(this.stateMachine);
                }
                else
                {
                    base.graphGUI.tool.AddBreadCrumb(this.stateMachine);
                }
                Event.current.Use();
            }
            if (UnityEditor.Graphs.AnimationStateMachine.Node.IsRightClick())
            {
                GenericMenu menu = new GenericMenu();
                menu.AddItem(new GUIContent("Copy"), false, new GenericMenu.MenuFunction(this.CopyStateMachineCallback));
                menu.ShowAsContext();
                Event.current.Use();
            }
        }

        public override UnityEngine.Object selectionObject
        {
            get
            {
                return this.stateMachine;
            }
        }

        public override string title
        {
            get
            {
                return (base.title + this.stateMachine.GetName());
            }
            set
            {
                base.title = value;
            }
        }

        public override UnityEngine.Object undoableObject
        {
            get
            {
                return AnimatorControllerTool.tool.stateMachineGraph.activeStateMachine;
            }
        }
    }
}

